import http from '@/utils/http'
import type { IAdmin } from '@/types'

//新增
export const adminAdd = (payload: IAdmin) => {
    return http.post('/api/manage/admin', payload)
}
//修改
export const adminEdit = (payload: IAdmin) => {
    return http.put(`/api/manage/admin`, payload)
}
//新增或修改
export const adminEditOrAdd = (payload: IAdmin) => {
    if (payload.id) {
        return adminEdit(payload)
    } else {
        return adminAdd(payload)
    }
}
//删除
export const adminDel = (id: number) => {
    return http.delete(`/api/manage/admin/${id}`)
}
//查询
export const adminList = () => {
    return http.get('/api/manage/admin')
}
//根据id查询一个
export const adminById = (id: number) => {
    return http.get(`/api/manage/admin/${id}`)
}

export const adminBatchDel = (delIds: number[]) => {
    const delTasks: Promise<IAdmin>[] = delIds.map(id => http.delete(`/api/manage/admin/${id}`))
    return Promise.all(delTasks)
}